package com.hc.core.util;

import java.io.FileInputStream;
import java.net.URL;
import java.util.Properties;

import javax.servlet.http.HttpServlet;

public class PropertiesTool extends HttpServlet {
	private static PropertiesTool instance = null;
	Properties properties = new Properties();

	/**
	 * 单态方法，供程序应用中获取该类的单态实例
	 * 
	 * @return
	 */
	public static PropertiesTool getInstance() {
		if (instance == null) {
			instance = new PropertiesTool();
			instance.init();
		}
		return instance;
	}

	public void init() {
		FileInputStream fs = null;
		try {
			String fileName = "column.properties";
			String filePath = PropertiesTool.class.getResource("/").getPath() + fileName;
			
			fs = new FileInputStream(filePath);
			properties.load(fs);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String getPropertiesValue(String propertiesName) {
		if (properties.containsKey(propertiesName)) {
			return properties.getProperty(propertiesName);
		} else {
			return null;
		}
	}
}
